# Author:Zhang Yu
# 统计所有线程运行后的总时间
import threading
import time
import random




def run(i):
    semaphore.acquire()
    print("runing", i,threading.current_thread())
    time.sleep(random.randint(1,3))
    semaphore.release()

if __name__ == '__main__':

    semaphore = threading.BoundedSemaphore(5)
    start_time = time.time()
    for i in range(50):
        t = threading.Thread(target=run,args=(i,))
        t.start()
while threading.active_count() != 1:
    pass
else:
    print("all done")